﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Xml;

using VDC.COMMON;
using VDC.COMMON.ExceptionHelpers;
using VDC.VONE.BLL;
using VDC.VONE.ENTITIES;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
using VDC.VONE.DAL;
using System.Web.Security;
using System.Collections.Generic;
using System.Reflection;
using VDC.VONE.BLL.ViewModel;
using System.Transactions;
using System.Text;
using System.Text.RegularExpressions;
using VDC.VONE.WSERIVCE;
using System.IO;
using System.Globalization;
using System.Net.Mail;



namespace VDC.VONE.WSERIVCE
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.None)]
    [ToolboxItem(false)]
    public class ServiceVOne : System.Web.Services.WebService
    {
        private const string AspnetsqlMembershipProvider = "AspNetSqlMembershipProvider";
        private const string AspnetADmembershipprovider = "AspNetADMembershipProvider";
        /*[======================Soap=============================]*/
        public class AuthenticationHeader : SoapHeader
        {
            public string UserName;
            public string Password;
        }

        public class UserManager
        {
            public UserManager() { }
            public bool Authenticate(string strUserName, string strPassword)
            {
                bool blnIsMemberShip = false;
                ConfigService configService = new ConfigService();

                if (!Roles.GetRolesForUser(strUserName).Contains("webservice"))
                    return false;

                if (configService.GetDefaultConfig() == Constants.Config.Sql)
                { // validte user on SQL
                    MembershipProvider membershipAdProvider = Membership.Providers[AspnetsqlMembershipProvider];
                    if (membershipAdProvider != null)
                    {

                        blnIsMemberShip = membershipAdProvider.ValidateUser(strUserName, strPassword);
                        UserRole a = new UserRole();

                        
                    }
                }
                else if (configService.GetDefaultConfig() == Constants.Config.Ldap)
                {
                    MembershipProvider membershipAdProvider = Membership.Providers[AspnetADmembershipprovider];
                    if (membershipAdProvider != null)
                    {
                        blnIsMemberShip = membershipAdProvider.ValidateUser(strUserName, strPassword);
                    }
                }
                return blnIsMemberShip;
            }
        }

        public AuthenticationHeader AuthHeader;
        bool IsAuthenticated
        {
            get
            {
                object state = Session["IsAuthenticated"];
                if (state != null) return (bool)state;
                IsAuthenticated = false;
                return false;
            }
            set
            {
                Session["IsAuthenticated"] = value;
            }
        }

        bool Authenticate(bool useCookie)
        {
            if (useCookie == false || IsAuthenticated == false)
            {
                UserManager userManager = new UserManager();
                bool authenticated = userManager.Authenticate(AuthHeader.UserName, AuthHeader.Password);
                //bool authenticated = true;
                IsAuthenticated = authenticated;
                return authenticated;
            }
            return true;
        }
        /*[================================Database============================================]*/

        #region [Câu 1] Lấy danh sách lĩnh vực
        /// <summary>
        /// Lấy danh sách lĩnh vực all
        /// </summary>
        /// <param name="groupName"></param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "GetProfileTypeGroupsAll", EnableSession = true)]
        public string GetProfileTypeGroupsAll()
        {

            //TiepNhanHoSo aaa = new TiepNhanHoSo();
            //aaa.ButtonTiepNhan();

            string xml = "";
            GetProfileTypeGroupsAllModel model = new GetProfileTypeGroupsAllModel();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot
                               + MethodBase.GetCurrentMethod().Name;

            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try
            {
                bool authentica = Authenticate(true);
                if (authentica == false)
                {
                    /*lổi đang nhập*/
                    model.status = 0;
                    model.message = "Error 1: Lỗi đang nhập thất bại!";
                    model.model = null;
                    return xml = jss.Serialize(model);
                }
                List<ProfileTypeGroup> data = (from a in (new ProfileTypeGroupData().GetProfileTypeGroups())
                                               select new ProfileTypeGroup()
                                               {
                                                   Name = a.Name,
                                                   ProfileTypeGroupId = a.ProfileTypeGroupId
                                               }).ToList();

                LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);

                model.status = 1;
                model.message = "Success: Thành công";
                model.model = data;

                return xml = jss.Serialize(model);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

                model.status = 0;
                model.message = string.Format("Error 2: {0}", ex.Message);
                return xml = jss.Serialize(model);
            }
        }
        #endregion

        #region [Câu 2] Lấy danh sách thủ tục theo lĩnh vực
        /// <summary>
        /// [Câu 2] Lấy danh sách thủ tục theo lĩnh vực
        /// </summary>
        /// <param name="IdProfileTyeGroups">Id lĩnh vực</param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "GetProfileTypeByProfileTypeGroups", EnableSession = true)]
        public string GetProfileTypeByProfileTypeGroups(int IdProfileTyeGroups)
        {
            string xml = "";
            GetProfileTypeByProfileTypeGroupsModel model = new GetProfileTypeByProfileTypeGroupsModel();
            JavaScriptSerializer jss = new JavaScriptSerializer();

            string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot
                             + MethodBase.GetCurrentMethod().Name;

            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);

            try
            {
                bool authentica = Authenticate(true);
                if (authentica == false)
                {
                    /*lổi đang nhập*/
                    model.status = 0;
                    model.message = "Error 1: Lỗi đang nhập thất bại!";
                    model.model = null;
                    return xml = jss.Serialize(model);
                }
                List<ProfileType> data = (from a in (new ProfileTypeData()).GetProfileTypes()
                                          where a.ProfileTypeGroupId == IdProfileTyeGroups
                                          select new ProfileType()
                                          {
                                              ProfileTypeId = a.ProfileTypeId,
                                              Code = a.Code,
                                              Name = a.Name,
                                              WorkflowId = a.WorkflowId,
                                              AmountProfile = a.AmountProfile,
                                              ResolveDays = a.ResolveDays,
                                              Fees = a.Fees,
                                              DepartmentId = a.DepartmentId,
                                              ProfileTypeGroupId = a.ProfileTypeGroupId,
                                              ImplementationListId = a.ImplementationListId,
                                              ResultsImplementationListId = a.ResultsImplementationListId
                                          }).ToList();
                model.status = 1;
                model.message = "Success: Thành công";
                model.model = data;

                LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);

                return xml = jss.Serialize(model);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

                model.status = 0;
                model.message = string.Format("Error 2: {0}", ex.Message);
                return xml = jss.Serialize(model);
            }
        }
        #endregion

        #region [Câu 3] Lấy thủ tục theo ID thủ tục (Ngày hiện trả)
        /// <summary>
        /// [Câu 3] Lấy danh sách thủ tục theo id thủ tục 
        /// </summary>
        /// <param name="IdProfileTyeGroups">Id thủ tục</param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "GetProfileTypeById", EnableSession = true)]
        public string GetProfileTypeById(int Id)
        {
            string xml = "";
            GetProfileTypeByIdModel model = new GetProfileTypeByIdModel();
            JavaScriptSerializer jss = new JavaScriptSerializer();

            string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot
                            + MethodBase.GetCurrentMethod().Name;

            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);

            try
            {
                bool authentica = Authenticate(true);
                if (authentica == false)
                {
                    /*lổi đang nhập*/
                    model.status = 0;
                    model.message = "Error 1: Lỗi đang nhập thất bại!";
                    model.model = null;
                    return xml = jss.Serialize(model);
                }
                ProfileType data = (from item in (new ProfileTypeData().GetProfileTypes())
                                    where item.ProfileTypeId == Id
                                    select new ProfileType()
                                    {
                                        ProfileTypeId = item.ProfileTypeId,
                                        Code = item.Code,
                                        Name = item.Name,
                                        WorkflowId = item.WorkflowId,
                                        AmountProfile = item.AmountProfile,
                                        ResolveDays = item.ResolveDays,
                                        Fees = item.Fees,
                                        DepartmentId = item.DepartmentId,
                                        ProfileTypeGroupId = item.ProfileTypeGroupId,
                                        ImplementationListId = item.ImplementationListId,
                                        ResultsImplementationListId = item.ResultsImplementationListId
                                    }).FirstOrDefault();
                model.status = 1;
                model.message = "Success: Thành công";
                model.model = data;

                LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);

                return xml = jss.Serialize(model);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

                model.status = 0;
                model.message = string.Format("Error 2: {0}", ex.Message);
                return xml = jss.Serialize(model);
            }
        }
        #endregion

        #region [Câu 4] Lấy yêu cầu thực hiện thủ tục hành chính theo ID thủ tục
        /// <summary>
        /// Câu 4] Lấy yêu cầu thực hiện thủ tục hành chính theo ID thủ tục
        /// </summary>
        /// <param name="IdProfileTyeGroups"></param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "GetRequirementsListByIdProfileType", EnableSession = true)]
        public string GetRequirementsListByIdProfileType(int IdProfileTye)
        {
            string xml = "";
            GetRequirementsListByIdProfileTypeModel model = new GetRequirementsListByIdProfileTypeModel();
            JavaScriptSerializer jss = new JavaScriptSerializer();

            string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot
                           + MethodBase.GetCurrentMethod().Name;

            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);

            try
            {
                bool authentica = Authenticate(true);
                if (authentica == false)
                {
                    /*lổi đang nhập*/
                    model.status = 0;
                    model.message = "Error 1: Lỗi đang nhập thất bại!";
                    model.model = null;
                    return xml = jss.Serialize(model);
                }
                List<RequirementsList> data = (from a in (new RequirementsListData().GetRequirementsLists())
                                               join b in (new ProfileTypeRequirementsListData().GetProfileTypeRequirementsLists()) on a.RequirementsListId equals b.RequirementsListId
                                               where b.ProfileTypeId == IdProfileTye
                                               select new RequirementsList
                                               {
                                                   RequirementsListId = a.RequirementsListId,
                                                   Name = a.Name
                                               }).ToList();

                model.status = 1;
                model.message = "Success: Thành công";
                model.model = data;

                LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);


                return xml = jss.Serialize(model);
            }
            catch (Exception ex)
            {

                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

                model.status = 0;
                model.message = string.Format("Error 2: {0}", ex.Message);
                return xml = jss.Serialize(model);
            }
        }

        #endregion

        #region [Câu 5] Lấy căn cứ pháp lý theo ID thủ tục
        /// <summary>
        /// [Câu 5] Lấy căn cứ pháp lý theo id thủ tục
        /// </summary>
        /// <param name="IdProfileTyeGroups"></param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "GetLegalGroundsListByIdProfileType", EnableSession = true)]
        public string GetLegalGroundsListByIdProfileType(int IdProfileTye)
        {
            string xml = "";
            GetLegalGroundsListByIdProfileTypeModel model = new GetLegalGroundsListByIdProfileTypeModel();
            JavaScriptSerializer jss = new JavaScriptSerializer();

            string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot
                          + MethodBase.GetCurrentMethod().Name;

            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);

            try
            {
                bool authentica = Authenticate(true);
                if (authentica == false)
                {
                    /*lổi đang nhập*/
                    model.status = 0;
                    model.message = "Error 1: Lỗi đang nhập thất bại!";
                    model.model = null;
                    return xml = jss.Serialize(model);
                }
                List<LegalGroundsList> data = (from a in (new ProfileTypeLegalGroundsListData().GetProfileTypeLegalGroundsLists())
                                               join b in (new LegalGroundsListData().GetLegalGroundsLists()) on a.LegalGroundsListId equals b.LegalGroundsListId
                                               where a.ProfileTypeId == IdProfileTye
                                               select new LegalGroundsList
                                               {
                                                   Name = b.Name,
                                                   LegalGroundsListId = b.LegalGroundsListId
                                               }).ToList();

                model.status = 1;
                model.message = "Success: Thành công";
                model.model = data;

                LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);

                return xml = jss.Serialize(model);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

                model.status = 0;
                model.message = string.Format("Error 2: {0}", ex.Message);
                return xml = jss.Serialize(model);
            }
        }

        #endregion

        #region [Câu 6] Lấy thành phần hồ sơ theo id thủ tục
        /// <summary>
        /// Lấy thành phần hồ sơ theo id thủ tục
        /// </summary>
        /// <param name="IdProfileTyeGroups"></param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "GetCompositionProfileListByIdProfileType", EnableSession = true)]
        public string GetCompositionProfileListByIdProfileType(int IdProfileTye)
        {
            string xml = "";
            GetCompositionProfileListByIdProfileTypeModel model = new GetCompositionProfileListByIdProfileTypeModel();
            JavaScriptSerializer jss = new JavaScriptSerializer();

            string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot
                         + MethodBase.GetCurrentMethod().Name;

            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);


            try
            {
                bool authentica = Authenticate(true);
                if (authentica == false)
                {
                    /*lổi đang nhập*/
                    model.status = 0;
                    model.message = "Error 1: Lỗi đang nhập thất bại!";
                    model.model = null;
                    return xml = jss.Serialize(model);
                }
                List<CompositionProfileList> data = (from a in (new CompositionProfileListData().GetCompositionProfileLists())
                                                     join b in (new ProfileTypeCompositionProfileListData().GetProfileTypeCompositionProfileLists()) on a.CompositionProfileListId equals b.CompositionProfileListId
                                                     where b.ProfileTypeId == IdProfileTye
                                                     select new CompositionProfileList
                                                     {
                                                         CompositionProfileListId = a.CompositionProfileListId,
                                                         Name = a.Name,
                                                         Code = a.Code
                                                     }).ToList();

                model.status = 1;
                model.message = "Success: Thành công";
                model.model = data;

                LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);


                return xml = jss.Serialize(model);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

                model.status = 0;
                model.message = string.Format("Error 2: {0}", ex.ToString());
                return xml = jss.Serialize(model);
            }
        }

        #endregion

        #region [Câu 7] Lấy danh sách trạng thái cấp
        /// <summary>
        /// Lấy danh sách trạng thái cấp
        /// </summary>
        /// <param name="groupName"></param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "GetLevelAll", EnableSession = true)]
        public string GetLevelAll()
        {
            string xml = "";
            GetLevelAllModel model = new GetLevelAllModel();
            JavaScriptSerializer jss = new JavaScriptSerializer();

            string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot
                        + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);

            try
            {
                bool authentica = Authenticate(true);
                if (authentica == false)
                {
                    /*lổi đang nhập*/
                    model.status = 0;
                    model.message = "Error 1: Lỗi đang nhập thất bại!";
                    model.model = null;
                    return xml = jss.Serialize(model);
                }
                List<Level> data = (from a in (new LevelData()).GetLevels()
                                    select new Level()
                                    {
                                        LevelId = a.LevelId,
                                        Name = a.Name,
                                    }).ToList();
                model.status = 1;
                model.message = "Success: Thành công";
                model.model = data;

                LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);

                return xml = jss.Serialize(model);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

                model.status = 0;
                model.message = string.Format("Error 2: {0}", ex.ToString());
                return xml = jss.Serialize(model);
            }
        }
        #endregion

        #region [Câu 8] Tra cưú hồ sơ theo mã
        /// <summary>
        /// Lấy danh sách trạng thái cấp
        /// </summary>
        /// <param name="groupName"></param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "GetProfileByCode", EnableSession = true)]
        public string GetProfileByCode(string code)
        {
            string xml = "";
            GetProfileByCodeModel model = new GetProfileByCodeModel();
            JavaScriptSerializer jss = new JavaScriptSerializer();

            string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot
                       + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);

            try
            {
                bool authentica = Authenticate(true);
                if (authentica == false)
                {
                    /*lổi đang nhập*/
                    model.status = 0;
                    model.message = "Error 1: Lỗi đang nhập thất bại!";
                    model.model = null;
                    return xml = jss.Serialize(model);
                }
                List<Profile> data = (from a in (new ProfileData()).GetProfiles()
                                      join b in (new ProfileStatusData()).GetProfileStatus() on a.ProfileStatusId equals b.ProfileStatusId
                                      where a.Code == code
                                      select new Profile()
                                    {
                                        ProfileId = a.ProfileId,
                                        Code = a.Code,
                                        Name = a.Name,
                                        ProfileTypeId = a.ProfileTypeId,
                                        ProfileStatusId = a.ProfileStatusId,
                                        ProfileStatusName = b.Name,
                                        SmsGet = a.SmsGet,
                                        Email = a.Email,
                                        CreateUserId = a.CreateUserId,
                                        CreateDate = a.CreateDate,
                                        ReceivingDate = a.ReceivingDate,
                                        AppointmentDate = a.AppointmentDate,
                                        LevelId = a.LevelId,
                                        Object = a.Object,
                                        SettlementDate = a.SettlementDate,
                                        Notes = a.Notes,
                                        Attachments = a.Attachments,
                                        ContentWork = a.ContentWork,
                                        StorageLocationProfileListId = a.StorageLocationProfileListId,
                                        IsDelete = a.IsDelete,
                                        OrganName = a.OrganName,
                                        Address = a.Address,
                                        Phone = a.Phone,
                                        AttachmentsOriginal = a.AttachmentsOriginal,
                                        IsOpen = a.IsOpen
                                    }).ToList();
                model.status = 1;
                model.message = "Success: Thành công";
                model.model = data;

                LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);

                return xml = jss.Serialize(model);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

                model.status = 0;
                model.message = string.Format("Error 2: {0}", ex.ToString());
                return xml = jss.Serialize(model);
            }
        }
        #endregion

        #region [Câu 9] Tiếp nhận hồ sơ
        /// <summary>
        /// Tiếp nhận hồ sơ
        /// </summary>
        /// <param name="groupName"></param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "TiepNhanHoSo", EnableSession = true)]
        public string TiepNhanHoSo(string tiepnhanhoso){
            string xml = "";
            ResulTiepNhanHoSoModel model= new ResulTiepNhanHoSoModel();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot  + MethodBase.GetCurrentMethod().Name;
            LogHelper.Instance.WriteInfo(Constants.Begin + methodName);
            try{
                bool authentica = Authenticate(true);
                if (authentica == false){/*lổi đang nhập*/
                    model.status = 0;
                    model.message = "Error 1: Lỗi đang nhập thất bại!";
                    return xml = jss.Serialize(model);
                }
                /*Convert json sang Object*/
                JavaScriptSerializer jss1 = new JavaScriptSerializer();
                jss1.MaxJsonLength = int.MaxValue;/*tăng kích thước cho json*/
                
                TiepNhanHoSoModel modeltiepnhan = jss1.Deserialize<TiepNhanHoSoModel>(tiepnhanhoso);

                

                /*Xét những giá trị defaul tiếp nhận*/
                modeltiepnhan.UserId = (new UserData()).GetUserByUserName(AuthHeader.UserName).UserId;
                model = (new VOneTiepNhan()).EventVOneTiepNhan(modeltiepnhan);

                LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
                LogHelper.Instance.WriteInfo(Constants.End + methodName);
                
                return xml = jss.Serialize(model);
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

                model.status = 0;
                model.message = string.Format("Error 2: {0}", ex.ToString());
                return xml = jss.Serialize(model);
            }
        }
        #endregion

        #region [Câu 10] Lấy danh sách kết quả thực hiện theo ID thủ tục
        /// <summary>
        /// Lấy danh sách kết quả thực hiện theo ID thủ tục
        /// </summary>
        /// <param name="groupName"></param>
        /// <returns></returns>
        [SoapHeader("AuthHeader")]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        [WebMethod(MessageName = "ResultsImplementatiorByIdProfileType", EnableSession = true)]
        public string ResultsImplementatiorByIdProfileType(int IdProfileTye) {
        string xml = "";
        ResultsImplementatiorByIdProfileTypeModel model = new ResultsImplementatiorByIdProfileTypeModel();
        JavaScriptSerializer jss = new JavaScriptSerializer();
        string methodName = MethodBase.GetCurrentMethod().DeclaringType + Constants.Dot
                   + MethodBase.GetCurrentMethod().Name;
        LogHelper.Instance.WriteInfo(Constants.Begin + methodName);

        try {
        bool authentica = Authenticate(true);
        if (authentica == false) {
        /*lổi đang nhập*/
        model.status = 0;
        model.message = "Error 1: Lỗi đang nhập thất bại!";
        model.model = null;
        return xml = jss.Serialize(model);
        }

        ResultsImplementatior data = (from a in (new ProfileTypeData()).GetProfileTypes()
                                      join b in (new ResultsImplementationListData().GetResultsImplementationLists()) on a.ResultsImplementationListId equals b.ResultsImplementationListId
                                             where a.ProfileTypeId == IdProfileTye
                                             select new ResultsImplementatior {
                                             ResultsImplementationListId = b.ResultsImplementationListId,
                                             Name= b.Name
                                             }).FirstOrDefault();

        model.status = 1;
        model.message = "Success: Thành công";
        model.model = data;

        LogHelper.Instance.WriteLog(HttpContext.Current.User.Identity.Name, methodName, false);
        LogHelper.Instance.WriteInfo(Constants.End + methodName);

        return xml = jss.Serialize(model);
        } catch (Exception ex) {
        LogHelper.Instance.WriteError(methodName + Constants.Colon + ex.Message);

        model.status = 0;
        model.message = string.Format("Error 2: {0}", ex.ToString());
        return xml = jss.Serialize(model);
        }
        }
        #endregion

    }
}


